def hanoi(n, x, y, z):
    if n == 1:
        print(x , " -> " , z)
    else:
        hanoi(n - 1, x, z, y)# 装 n - 1 个盘子移动到 z 上
        print(x, ' -> ', z)
        hanoi(n - 1, y, x, z)
number = int(input('请输入汉诺塔层数：'))
hanoi(number,'X','Y','Z')
